|
|
|
|
|
|
|
As is the case when you are enlarging an image, you should consider the output pixels and determine which input pixels contribute to each output pixel. You can use the same equations described in the previous section for enlarging an image. An output pixel at location (x_out, y_out) maps back to an input position (x_in, y_in) where: |
|
|
|
 |
|
|
|
|
x_in = FromXmin + (ix_out - ToXmin) / XScale
y_in = FromYmin + (iy_out - ToYmin) / YScale |
|
|
|
|
|
|
|
|
With these equations, the input pixels that map into the output pixel (x_out, y_out) are those with x1 <= x <= x2 and y1 <= y <= y2 where: |
|
|
|
 |
|
|
|
|
x1 = Int(FromXmin + (ix_out - ToXmin) / XScale)
x2 = Int(FromXmin + (ix_out + 1 - ToXmin) / XScale) - 1
yl = Int(FromYmin + (iy_out - ToYmin) / YScale)
y2 = Int(FromYmin + (iy_out + 1 - ToYmin) / YScale) - 1 |
|
|
|
|
|
|
|
|
You can now take the average over the values of the input pixels in this area to find the correct value for the output pixel (x_out, y_out). |
|
|
|
|
|
|
|
|
Example program Reduce, shown in Figure 7.16, uses this technique to shrink images without severe aliasing. The most interesting part of the program's TransformImage subroutine is shown in the following code. The rest of the program is very similar to the other image transformation programs described in this chapter so it is not shown here. You can find the complete source code on the CD-ROM. |
|
|
|
 |
|
|
|
|
' Calculate the output pixel values. For iy_out = 0 To pic_to.ScaleHeight - 1
For ix_out = 0 To pic_to.ScaleWidth - 1 ' Map the pixel value from
' (ix_out, iy_out) to (x_in, y_in). xl = Int(FromXmin + (ix_out - ToXmin) / XScale)
x2 = Int(FromXmin + _
(ix_out + 1 - ToXmin) / XScale) - 1
y1 = Int(FromYmin + (iy_out - ToYmin) / YScale) |
|
|
|
|
|
|
|
|
Figure 7.16
Program Reduce reduces an
image without severe aliasing. |
|
|
|
|
|